package trip

import grails.converters.*

class AirportMappingController {
    def scaffold = true

    def index() { 
        redirect(action: "list")
    }
	
    def iata = {
      def iata = params.id?.toUpperCase() ?: "NO IATA"
      def airport = AirportMapping.findByIata(iata)
      if(!airport)
	  {
		if(!SetNewAirport(iata))
		{
			airport = new AirportMapping(iata:iata, name:"Not found")
		}
		else
		{
			airport = AirportMapping.findByIata(iata)
		}
      }
      render airport as JSON
    }

	private boolean SetNewAirport(String airName)
	{	
		boolean rtnSuccess = false
		//from: http://ws.geonames.org/search?name_equals=pwm&fcode=airp&type=json
		return rtnSuccess
	}
}

